﻿@model CREAPA.Dominio.Cargo

@{
    ViewBag.Title = "Alterar";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Alterar Cargos</h2>

@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Cargo</legend>

        @Html.HiddenFor(model => model.Id)

        <p><div class="editor-label">
            @Html.LabelFor(model => model.Nome)
        </div>
        <div class="editor-field">
        <div class="login-msg">
            @Html.EditorFor(model => model.Nome)
            @Html.ValidationMessageFor(model => model.Nome)
        </div></p>

        <p>
            <input type="submit" value="Alterar" class="button" />
            @Html.ActionLink("Voltar", "Index",null,new { @class = "button2" })
        </p>
    </fieldset>
}

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}
<script>
    jQuery(document).ready(function () {
        // verifica se existe algum elemento com a class
        if ($(".button").length) {
            // adiciona evento desabilitando o botão
            $(".button").on('click', function () {
                $(this).attr({
                    disabled: true
                });
                // descobrindo o form pai e enviando
                this.value = 'Enviando...';
                $(this).parents('form:first').submit();
            });
        }
    });
</script>